package org.example.controller;

import org.example.domain.Employee;
import org.example.domain.EmployeeTMP;
import org.example.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("/findAll")
    public String findAll(Model model) {
        List<EmployeeTMP> employees = employeeService.findAll();
        model.addAttribute("list",employees);
        return "list";
    }

    @RequestMapping("/save")
    public String save(Employee e) {
        employeeService.save(e);
        return "redirect:/findAll";
    }
}
